<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" arrow>
				<view class="item" @click="showAct(item,index)">
					<view class="line-cars">
						<fui-text text="车牌号：" color="#afafaf" :size="28" align="right" block style="width: 120rpx;"></fui-text>
						<view class="right-box">
							<block v-for="(plate,i) in item.plates" :key="i">
							<platetype :plate_number="plate.plate_number" :plate_type="plate.plate_type"></platetype>
							<text style="color: #fff;">..</text>
							</block>
						</view>
					</view>
					<view class="line">
						<fui-text text="车主：" color="#afafaf" :size="28" align="right" block style="width: 120rpx;"></fui-text>
						<fui-text :text="item.contact+' - '+item.mobile" color="black" :size="28"></fui-text>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<filter :param="param" @confirm="doSubmit"></filter>
		<fui-modal v-if="buttons" :show="act.show" descr="请选择操作" :buttons="buttons" :radius="16" :maskClosable="true" direction="column" @click="clickButton" @cancel="cancelButton"></fui-modal>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDateTime,parseNumber} from '@/utils/util.js'
	import platetype from '@/components/common/platetype.vue';
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			platetype:platetype,
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				type_txt:{
					monthly:'月租车',
					day:'日租车',
					stored:'储值车',
					member:'会员车',
					vip:'VIP车'
				},
				list:[],
				page:1,
				endData:false,
				param:{
					plate_number:'',
					contact:'',
					mobile:''
				},
				act:{
					show:false,
					index:'',
					item:''
				},
				buttons:[
					{
						text: '还原',
						background: '#22b2ff',
						value:'restore'
					},
					{
						text: '彻底删除',
						background: '#ff0000',
						value:'delete'
					}
				]
			}
		},
		onLoad(e) {
			this.getList();
		},
		onShow() {
			let refresh=uni.getStorageSync('refresh') || '';
			if(refresh){
				this.list=[];
				this.page=1;
				this.endData=false;
				uni.setStorageSync('refresh','');
				this.getList();
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			parseNumber,
			formatDateTime:function(e){
				return formatDateTime(new Date(e*1000)).slice(0,10);
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/cars/list',{
					...this.param,
					recyclebin:1,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			},
			showAct:function(item,index){
				this.act={
					show:true,
					index:index,
					item:item
				};
			},
			clickButton:function(e){
				let id=this.act.item.id;
				let index=this.act.item.index;
				let rules_type=this.act.item.rules_type;
				if(e.value=='edit'){
					this.$navigateTo('parking/cars/detail?rules_type='+rules_type+'&cars_id='+id);
				}
				if(e.value=='recharge'){
					this.$navigateTo('parking/cars/recharge?cars_id='+id);
				}
				if(e.value=='log'){
					this.$navigateTo('parking/cars/log?rules_type='+rules_type+'&cars_id='+id);
				}
				if(e.value=='delete'){
					uni.showModal({
						content:'您确定要删除该车辆吗？',
						success:(e)=>{
							if(e.confirm){
								this.$post('parking/cars/del',{id:id},true,true).then(res=>{
									this.list.splice(index,1);
								});
							}
						}
					})
				}
				this.cancelButton();
			},
			cancelButton:function(){
				this.act={
					show:false,
					index:'',
					item:''
				};
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	.line{
		display: flex;
		align-items: center;
		width:100%;
		height: 70rpx;	
	}
	.line-cars{
		display: flex;
		flex-wrap: wrap;
		width:100%;
		align-items: center;
		.right-box{
			width: 75%;
		}
	}
}
</style>